package com.sc.smartcommunity.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.smartcommunity.domain.Mall;
import com.sc.smartcommunity.mapper.MallMapper;
import com.sc.smartcommunity.service.MallService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallServiceImpl extends ServiceImpl<MallMapper, Mall> implements MallService {

    @Resource
    private MallMapper mallMapper;

    @Override
    public List<Mall> getAllMalls(Integer type) {
        //根据距离排序
        switch (type) {
            case 1: //根据最短距离排序
                return mallMapper.selectList(new LambdaQueryWrapper<Mall>().orderByDesc(Mall::getDistance));
            case 2: //根据评分排序
                return mallMapper.selectList(new LambdaQueryWrapper<Mall>().orderByAsc(Mall::getScore));
            case 3: //根据销量排序
                return mallMapper.selectList(new LambdaQueryWrapper<Mall>().orderByDesc(Mall::getSalesVolume));
            default: //销量高 -> 低
                return mallMapper.selectList(null);
        }
    }
}